package com.ctgu.controller;

import com.ctgu.entity.Product;
import com.ctgu.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("product")

public class DetailController {
    @Autowired
    private DetailService detailService;

    @RequestMapping("id")
    public String id(Model model, int id){
    Product list = detailService.findById(id);
        model.addAttribute("product_list",list);
    return "detail";
    }

    @RequestMapping("addProduct")
    public String addProduct(int product_id,  HttpServletRequest request){
        int user_id = (int)request.getSession().getAttribute("user_id");
        detailService.addProduct(product_id,user_id,1);
        return "redirect:id?id="+product_id;
    }

}
